package henu.dao.impl;
import henu.bean.TuitionProfessionalControl;
import henu.dao.TuitionProfessionalControlDao;
import henu.util.Dhcp;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
public class TuitionProfessionalControlDaoImpl  implements TuitionProfessionalControlDao{

	@Override
	public int save(TuitionProfessionalControl tpc) {
		// TODO Auto-generated method stub
		int result = 0;
		try {
			QueryRunner qr = new QueryRunner(Dhcp.getDataSource());
			String sql = "insert into from TuitionProfessionalControl(sId,profession,tuition,costItemNumber,revenueCost,paidCost,deferredCost,audit,remarks) values(?,?,?,?,?,?,?,?,?)";
			Object[] params = {tpc.getsId(),tpc.getProfession(),tpc.getTuition(),tpc.getCostItemNumber(),tpc.getRevenueCost(),tpc.getPaidCost(),tpc.getDeferredCost(),tpc.getAudit(),tpc.getRemarks()};
			result = qr.update(sql, params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public int delete(String sId) {
		// TODO Auto-generated method stub
		int result = 0;
		try {
			QueryRunner qr = new QueryRunner(Dhcp.getDataSource());
			String sql = "delete from TuitionProfessionalControl where sId = ?";
			result = qr.update(sql, sId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public int update(String sId, TuitionProfessionalControl tpc) {
		// TODO Auto-generated method stub
		int result = 0;
		try {
			QueryRunner qr = new QueryRunner(Dhcp.getDataSource());
			String sql = "update from TuitionProfessionalControl where sId = ?";
			Object[] params = {tpc.getAudit(),tpc.getCostItemNumber(),tpc.getDeferredCost(),tpc.getPaidCost(),tpc.getProfession(),tpc.getRemarks(),tpc.getRevenueCost(),tpc.getTuition()};
			result = qr.update(sql, params,sId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<TuitionProfessionalControl> findAll(String order, String sort) {
		// TODO Auto-generated method stub
		List<TuitionProfessionalControl> list = new ArrayList<TuitionProfessionalControl>();
		QueryRunner qr = new QueryRunner(Dhcp.getDataSource());
		String sql = " select * from TuitionProfessionalControl where order = ? and sort = ?";
		Object[] params = {order,sort};
		try {
			list = qr.query(sql, new BeanListHandler<TuitionProfessionalControl>(TuitionProfessionalControl.class), params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public TuitionProfessionalControl findBySid(String sId) {
		// TODO Auto-generated method stub
		TuitionProfessionalControl tpc = new TuitionProfessionalControl();
		try {
			QueryRunner qr = new QueryRunner(Dhcp.getDataSource());
			String sql = "select * from TuitionProfessionalControl where sId = ?";
			tpc = qr.query(sql, new BeanHandler<TuitionProfessionalControl>(TuitionProfessionalControl.class), sId);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tpc;
	}

	@Override
	public int audit(String sId) {
		// TODO Auto-generated method stub
	    int result = 0;
	    
		return result;
	}

	@Override
	public double sumCost(String sId) {
		// TODO Auto-generated method stub
		
		return 0;
	}

	@Override
	public double stastistic(String statistics, String item, String condition) {
		// TODO Auto-generated method stub
		
		return 0;
	}

}
